/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Response;

import Request.Request;
import Request.LoginRequest;
import Request.RegisterRequest;
import java.io.*;
import java.net.*;
import java.util.*;

import AccManager.UserProfile;

/**
 *
 * @author lcy
 */
public abstract class NetDataResponse implements Serializable {

    protected String result_msg;
    protected boolean _data_valid;
    protected Request _request;
    protected InetSocketAddress _sock_addr;
    protected RespType _resp_type;

    public NetDataResponse(){
        InitCommComponents();
    }

    private void InitCommComponents(){
        _data_valid = true;
        result_msg = "";
        _request = null;
    }

    public static NetDataResponse CreateResponse(Request r){
        switch(r.GetRequestType()){
            case LOGIN:
            case REGISTRATION:
                try{
                    return new NetDataLRResp();
                }catch(UnknownHostException ex){
                    return null;
                }
            case USERLIST:
                List<UserProfile> profile_list = new ArrayList<UserProfile>();
                return new NetDataUserListResp(profile_list);
            case PROBE:
                return null;
        }

        return null;
    }

    public void SetResultMsg(String msg){
        result_msg = msg;
    }

    public void AppendResultMsg(String msg){
        result_msg += msg;
    }

    public String GetResultMsg(){
        return result_msg;
    }

    public abstract Object GetResponseContent();

    public Request GetRequest(){
        return _request;
    }

    public abstract void SetRequest(Request request);

    //public abstract void SetResponseContent();

    public boolean IsDataFormatValid(){
        return _data_valid;
    }

    public void SetDataFormatValid(boolean value){
        _data_valid = value;
    }

    public void SetInetSockAddr(InetSocketAddress addr){
        _sock_addr = addr;
    }

    public InetSocketAddress GeInetAddr(){
        return _sock_addr;
    }

    public RespType GetRespType(){
        return _resp_type;
    }
}
